#pragma once

#include "global.h"
extern LPDIRECT3DDEVICE9 d3ddev;
GameArt::GameArt() {
	m_center	= D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	m_position	= D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	m_scaling	= D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	m_angle		= 0.0f;

	
}

GameArt::~GameArt() { 
}
D3DXIMAGE_INFO GameArt::getInfo() {
	return m_imageInfo;
}

void GameArt::Create(char* file,  D3DXVECTOR3 position, D3DXVECTOR3 scale, float angle)
{
	D3DXCreateSprite(d3ddev, &m_sprite); // Create the Sprite OBJECT
	
	// Attain the Texture
	D3DXCreateTextureFromFileEx(d3ddev, 
								file, 
								D3DX_DEFAULT_NONPOW2, 
								D3DX_DEFAULT_NONPOW2, 
								0, 
								0,
								D3DFMT_UNKNOWN, 
								D3DPOOL_MANAGED, D3DX_DEFAULT,
								D3DX_DEFAULT, 
								D3DCOLOR_XRGB(255, 0, 255), // Background of image should be magenta
								&m_imageInfo, 
								0, 
								&m_texture);

	m_center = D3DXVECTOR3(	m_imageInfo.Width  * 0.5,	// Center of the Image
							m_imageInfo.Height * 0.5, 
							0.0f);
	m_position	= position;								// Position of the Image
	m_scaling	= scale;								// Size of the Image
	m_angle		= angle;								// Angle of the Image
}
D3DXVECTOR3 GameArt::getCenter() {
	return m_center;
}

void GameArt::Draw(RECT r)
{
	m_sprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_FRONTTOBACK);

	D3DXMATRIX transMat, rotMat, scaleMat, worldMat;
	D3DXMatrixIdentity(&transMat);
	D3DXMatrixIdentity(&scaleMat);
	D3DXMatrixIdentity(&rotMat);
	D3DXMatrixIdentity(&worldMat);

	D3DXMatrixScaling(&scaleMat, m_scaling.x, m_scaling.y, m_scaling.z);			
	D3DXMatrixRotationZ(&rotMat, D3DXToRadian(m_angle));		
	D3DXMatrixTranslation(&transMat, m_position.x, m_position.y, m_position.z);	
	D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);		
	D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);

	m_sprite->SetTransform(&worldMat);
	m_sprite->Draw(	m_texture, 
					&r, 
					&m_center,
					&D3DXVECTOR3(400,300,0), // Starting position of image
					D3DXCOLOR(255, 255, 255, 255));
	m_sprite->End();
}

void GameArt::Shutdown()
{
	SAFE_RELEASE(m_sprite);
	SAFE_RELEASE(m_texture);
}

ID3DXSprite*		GameArt::getSprite()		{return m_sprite;}	
IDirect3DTexture9*	GameArt::getTexture()		{return m_texture;}
D3DXIMAGE_INFO		GameArt::getImageInfo()		{return m_imageInfo;}

D3DXVECTOR3			GameArt::getPos()			{return m_position;}
D3DXVECTOR3			GameArt::getScale()			{return m_scaling;}
float				GameArt::getAngle()			{return m_angle;}

void				GameArt::setPos(D3DXVECTOR3 value)  {m_position = value;}
void				GameArt::setScale(D3DXVECTOR3 value){m_scaling = value;}
void				GameArt::setAngle(float value)		{m_angle = value;}


